#ifndef REPORT_PROTOCOL_H
#define REPORT_PROTOCOL_H
#ifdef ignore
#undef ignore
#endif
#include <semaphore.h>
#include <list>
#include "timer.h"
#include <fstream>
#include "nano_db.h"
//#define ReportInterfacePtr ReportInterface::ptr()
/*typedef struct 
{
    uint64_t uptime;
    U8 slotId;
    U8 *imsi;
    U8 *imei;
    U8 *tmsi;
} phoneInfo_t;*/

class ReportInterface
{
public: 
     
     ReportInterface();
     void initReport();
     virtual bool initialze(){return true ;}
     virtual bool CommitData(){return false;}
     virtual bool saveData(uint8_t *paraValue){return false;}
     virtual bool ReportPrepare(){return false;}
     virtual bool DataReport(){return false;}
     virtual bool ReportSuccess(){return false;}
     bool saveConfig(const char *name , const char *value);
     bool saveConfig(const char *name , const uint64_t value);
     bool saveConfig(const char *name , const uint32_t value);

     virtual bool initialzedM(){return false;}  
     virtual ~ReportInterface(){}
     
     char* returnMac12();
     char* returnMac18();
     bool getReportState();
     void SetReportState(bool state);
     sem_t* getSem();
     uint16_t getcmdIndex();
     bool packGetDataMsg();
     bool packUploadAck();
     bool packStopUpload();
     void setTime(uint64_t uptime);
     uint64_t getTime();
     void setReportIntvl(int32_t intvl);
     int32_t getReportIntvl();
     struct ndb_t *getndb();
     bool getcmdRsp(char *cmd, char *rspdata, int32_t *data_len);
     

private:
     sem_t sem_report;
     struct ndb_t ndb;
     uint16_t cmdIndex;
     bool reportSuccess;
     uint32_t ReportIntvl;
     uint64_t uploadTime;
     void getmac();
     char mac12[12];
     char mac18[18];     
     TimerElement<ReportInterface> getDataTimeOut_;
     void handleGetDataTmOut();

};
inline struct ndb_t *ReportInterface::getndb()
{
    return &ndb;
}

inline int32_t ReportInterface::getReportIntvl()
{
    return ReportIntvl;
}

inline void ReportInterface::setTime(uint64_t uptime)
{
    uploadTime = uptime;
}

inline uint64_t ReportInterface::getTime()
{
    return uploadTime;
}

class ReportPhone
{
public:
    ReportPhone();
    char imsi[16];
    char imei[16];
    char tmsi[16];
    uint32_t slotId;
    uint64_t uptime;

};

#ifdef HTTP
#define ReportInterfacePtr HttpReport::ptr()
class HttpReport:public ReportInterface
{
public:
    HttpReport();
    virtual ~HttpReport();
    static HttpReport *ptr();	
    virtual bool initialze();
    virtual bool CommitData();
    virtual bool ReportPrepare();
    virtual bool saveData(uint8_t *paraValue);
    virtual bool DataReport();
    virtual bool ReportSuccess(); 
    virtual bool initialzedM();
    uint32_t recordSize();
    

private:
    HttpReport(const HttpReport&);
    HttpReport& operator = (const HttpReport&);
    std::list<ReportPhone> phoneList_;

    bool initialzed;
    char filename[128];
    char recordPath[128];
    char mac12[12];
    char mac18[18];
    char addr[128];
    char dataType[16];
    char place[16];
    char protocol[16];
    char md5Key[16];
    
    
     
   
};

inline HttpReport* HttpReport::ptr()
{
    static HttpReport instance;
    return &instance;
}
#endif
#ifdef FTP
#define ReportInterfacePtr FtpReport::ptr()	
class FtpReport:public ReportInterface
{
public:
    FtpReport();
    virtual ~FtpReport();
    static FtpReport *ptr();	
    virtual bool initialze();
    virtual bool CommitData();
    virtual bool ReportPrepare();
    virtual bool saveData(uint8_t *paraValue);
    virtual bool DataReport();
    virtual bool ReportSuccess(); 
    virtual bool initialzedM();
    uint32_t recordSize();

private:
    FtpReport(const FtpReport&);
    FtpReport& operator = (const FtpReport&);
    std::list<ReportPhone> phoneList_;
    bool initialzed;
    char filename[128];
    char recordPath[128];
    char mac12[12];
    char mac18[18];
    char addr[128];
    int32_t port;
    char usr[128];
    char password[128];
    char deviceId[16];
    char company[128];
    char BSIC[16];

};


inline FtpReport* FtpReport::ptr()
{
    static FtpReport instance;
    return &instance;
}
#endif
#endif
